package cn.com.zhbs.common.util;

import com.alibaba.fastjson.JSONObject;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author 陈治杰
 * @Title: Request
 * @Description:
 * @date 2019/1/3120:10
 */
public class Request {

    public static JSONObject getRequestPostData(HttpServletRequest request){
     try{
         int contentLength = request.getContentLength();
         if(contentLength<0){
             return null;
         }
         byte buffer[] = new byte[contentLength];
         for (int i = 0; i < contentLength;) {
             int len = request.getInputStream().read(buffer, i, contentLength - i);
             if (len == -1) {
                 break;
             }
             i += len;
         }
         return JSONObject.parseObject(new String(buffer, "utf-8"));
     }catch (Exception e){
         e.printStackTrace();
         return null;
     }
     }
}
